﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;

namespace KitBuildingWF.Views
{
    public partial class ReportViewForm : Form
    {
        private DataSet1 kitDataSet = null;

        public ReportViewForm()
        {
            InitializeComponent();
        }

        public void SetDataSource(DataSet1 ds)
        {
            this.kitDataSet = ds;
        }

        private void ReportView_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dataSet1.KitBRprt' table. You can move, or remove it, as needed.
            //this.kitBRprtTableAdapter.Fill(this.dataSet1.KitBRprt);
  
            BindingSource kitBindingSource = new BindingSource();
            kitBindingSource.DataMember = "KitBRprt";
            kitBindingSource.DataSource = kitDataSet;
            ReportDataSource rds = new ReportDataSource();
            rds.Name = "CalculateReportDataset";  // ***** This name has to match the dataset name used for the report
            rds.Value = kitBindingSource;

            reportViewer1.Reset();
            reportViewer1.LocalReport.ReportPath = "Reports\\CalculateReport.rdlc";
            reportViewer1.LocalReport.DataSources.Clear();
            reportViewer1.LocalReport.DataSources.Add(rds);
             
            reportViewer1.RefreshReport();
            
        }



        private void ReportView_FormClosing(object sender, FormClosingEventArgs e)
        {
            // workaround for the error occuring on closing report view panel 
            this.reportViewer1.LocalReport.ReleaseSandboxAppDomain();
        }

        /// <summary>
        /// Get the report viewer handler in this report panel
        /// </summary>
        /// <returns></returns>
        public ReportViewer GetReportViewer()
        {
            return reportViewer1;
        }

        private void kitBRprtBindingSource_CurrentChanged(object sender, EventArgs e)
        {

        }


    }
}
